package com.xiedafeng.www.view;

import com.xiedafeng.www.controller.LoginController;
import com.xiedafeng.www.controller.RegisterController;
import com.xiedafeng.www.po.User;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.applet.Applet;

/**
 * @author xiedafeng
 */
public class LoginView extends Application {
    public static void main(String[] args) {
        launch(args);
    }
    @Override
    public void start(Stage primaryStage) {
        TextField userNameField =new TextField();
        PasswordField passwordField =new PasswordField();
        Text userName=new Text();
        userName.setText("账号");
        Text password=new Text();
        password.setText("密码");
        Button login=new Button("登录");
        Button register=new Button("注册");
        GridPane gridPane=new GridPane();
        gridPane.add(userName,0,0);
        gridPane.add(userNameField,1,0);
        gridPane.add(passwordField,1,1);
        gridPane.add(password,0,1);
        gridPane.add(login,1,2);
        gridPane.add(register,1,3);
        gridPane.setAlignment(Pos.CENTER);

        Scene sc=new Scene(gridPane);
        primaryStage.setScene(sc);
        primaryStage.show();
        register.setOnMouseClicked(event ->register());
        login.setOnMouseClicked(event -> {
            try {
                loginCheck(userNameField,passwordField);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
    private static void register(){
        RegisterController registerController=new RegisterController();
        registerController.create();
    }
    private static void loginCheck(TextField userNameField,PasswordField passwordField) {
        User user= new User();
        user.setUserName(userNameField.getText());
        user.setPassword(passwordField.getText());
        LoginController loginController=new LoginController();
        loginController.login(user);
    }
}
